unit distaara;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, StdCtrls, Buttons, ExtCtrls, Wwdbigrd, Wwdbgrid, siComp,
  siLngLnk;

type
  TfDisTara = class(TForm)
    dbGrid1: TwwDBGrid;
    GroupBox1: TGroupBox;
    Edit3: TEdit;
    RadioEdit3: TRadioButton;
    RadioEdit2: TRadioButton;
    Edit2: TEdit;
    Edit1: TEdit;
    RadioEdit1: TRadioButton;
    Panel1: TPanel;
    BitBtn2: TBitBtn;
    BitBtn1: TBitBtn;
    RadioEdit4: TRadioButton;
    Edit4: TEdit;
    RadioEdit5: TRadioButton;
    Edit5: TEdit;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1Enter(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);

    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure Edit1Exit(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure Edit4KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit5KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fDisTara: TfDisTara;
  str: string;
implementation

uses ana1, udmTeknik;

{$R *.DFM}

procedure TfDisTara.BitBtn1Click(Sender: TObject);
begin
  modalresult := mrcancel;
end;

procedure TfDisTara.BitBtn2Click(Sender: TObject);
begin
  modalresult := mrok;
end;

procedure TfDisTara.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if (key = #13) and (dmTeknik.spdistakiparama.active) then
  begin
    key := #0;
    bitbtn2.Click;
  end
  else
  begin
    if ord(key) <> 8 then
      str := str + key
    else
      delete(str, length(str), 1);

    if RadioEdit1.Checked then
      edit1.setfocus
    else
      if RadioEdit2.Checked then
        edit2.setfocus
      else
        if RadioEdit3.Checked then
          edit3.setfocus
        else
          if RadioEdit4.Checked then
            edit4.setfocus;
  end;
end;

procedure TfDisTara.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_down then
  begin
    edit3.SetFocus;
  end;

  if key = vk_up then
  begin
    edit4.SetFocus;
  end;

end;

procedure TfDisTara.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_down then
  begin
    edit4.SetFocus;
  end;
end;

procedure TfDisTara.Edit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_up then
  begin
    edit2.SetFocus;
  end;

  if key = vk_down then
  begin
    edit5.SetFocus;
  end;
end;

procedure TfDisTara.Edit1Enter(Sender: TObject);
begin
  edit1.Color := clbtnface;
  edit2.Color := clbtnface;
  edit3.Color := clbtnface;
  edit4.Color := clbtnface;
  edit5.Color := clbtnface;

  edit1.text := '';
  edit2.text := '';
  edit3.text := '';
  edit3.text := '';
  edit4.text := '';
  edit5.text := '';

  TRadioButton(FindComponent('Radio' + TEdit(Sender).Name)).Checked := True;
  TEdit(Sender).Color := clWhite;
  TEdit(Sender).text := Str;
  TEdit(Sender).SelectAll;
  TEdit(Sender).SelText := Str;
end;

procedure TfDisTara.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
  begin
    key := #0;
    dmTeknik.spdistakiparama.Close;
    dmTeknik.spdistakiparama.Parameters.parambyname('@no').Value := TEdit(Sender).Tag;
    dmTeknik.spdistakiparama.Parameters.parambyname('@aranan').Value := TEdit(Sender).text;
    dmTeknik.spdistakiparama.open;

    if dmTeknik.spdistakiparama.RecordCount > 0 then
      dbgrid1.setfocus;
  end;

end;

procedure TfDisTara.FormCreate(Sender: TObject);
begin
  keypreview := true;
  str := '';
  anaform.CreateExport(Self);
end;

procedure TfDisTara.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

  if dmTeknik.spdistakiparama.active then
  begin
    if key = vk_next then
    begin
      dmTeknik.spdistakiparama.Next;
    end;

    if key = vk_prior then
    begin
      dmTeknik.spdistakiparama.prior;
    end;

    if key = vk_f2 then
    begin
      bitbtn2.click;
    end;

  end;
end;

procedure TfDisTara.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #10 then
  begin
    key := #0;
    bitbtn2.Click;
  end;
  if key = #27 then
  begin
    key := #0;
    modalresult := mrcancel;
  end;

end;

procedure TfDisTara.Edit1Exit(Sender: TObject);
begin
//  str := Tedit(Sender).text;
end;

procedure TfDisTara.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action := cafree;
  fDisTara := nil;
end;

procedure TfDisTara.DBGrid1DblClick(Sender: TObject);
begin
  bitbtn2.Click;
end;

procedure TfDisTara.Edit4KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_down then
  begin
    edit2.SetFocus;
  end;

  if key = vk_up then
  begin
    edit1.SetFocus;
  end;
end;

procedure TfDisTara.Edit5KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = vk_up then
  begin
    edit3.SetFocus;
  end;
end;

end.

